﻿


//当列表没有选中任何一列时，返回true；
function listIfSelectNone(){
  if(listSelectNum<=0)
    return true;
  else
    return false;
}

//当列表选中超过一列（两列或两列以上）时，返回true；
function listIfSelectMore(){
  if(listSelectNum>1)
    return true;
  else
    return false;
}

//返回列表当前选中值，如果有多个，值和值之间用","分隔；当hiddenCheckboxObj==null或没有选中任何记录或选中了一条记录但记录值确实为""时，返回值都会是""；
function listGetValue(){
  var hiddenCheckboxObj = document.all.item("hiddenCheckbox");
  var returnValue="";
  if(hiddenCheckboxObj.length==null){
    if(hiddenCheckboxObj.checked)
      returnValue=hiddenCheckboxObj.value;
  }else{
    for(i=0;i<hiddenCheckboxObj.length;i++){
      if(hiddenCheckboxObj[i].checked){
        if(returnValue=="")
          returnValue=hiddenCheckboxObj[i].value;
        else
          returnValue=returnValue+","+hiddenCheckboxObj[i].value;
      }
    }
  }
  return returnValue;
}

//完成对hiddenCheckbox的全选和全不选操作
function listAllorNone(){
	
  var obj = $("AllorNone");
  if(obj.checked){
    listSelectAll();
    obj.title="全不选";
  }
  if(!obj.checked){
    listSelectNone();
    obj.title="全选";
  }
}

//全选
function listSelectAll(){
	  var hiddenCheckboxObj = $name("query_checkbox");
	  if(hiddenCheckboxObj==null)
		return;
	  if(hiddenCheckboxObj.length==null){
		hiddenCheckboxObj.checked = true;
		listSelectNum=1;
	  }else{
		for(i=0;i<hiddenCheckboxObj.length;i++){
		   hiddenCheckboxObj[i].checked  = true;
		}
		listSelectNum=hiddenCheckboxObj.length;
	  }
}

//全不选
function listSelectNone(){
  var hiddenCheckboxObj = $name("query_checkbox");
  if(hiddenCheckboxObj==null)
    return;
	
  if(hiddenCheckboxObj.length==null){
    hiddenCheckboxObj.checked = false;
  }else{
    for(i=0;i<hiddenCheckboxObj.length;i++){
      hiddenCheckboxObj[i].checked = false;
    }
  }
  listSelectNum=0;
}

/**
* 得到一条记录编号
*/
function getOneRecord(){
    var sRecordID,sFeatures,sHref;
	var count = 0;
    var ob_arr = $name("query_checkbox");
    if (ob_arr == null)
    {
        alert("请选择记录！");
        return;
    }else{
        if (ob_arr.length == null){
            if(ob_arr.checked)
                sRecordID = ob_arr.value;
            else{
                alert("请选择记录！");
                return;
            }
        }else{
            for (i=0;i<ob_arr.length;i++){
                if (ob_arr[i].checked == true){
					if(count != 0){
						if(confirm("此操作为单选，你选择了多条记录，是否取第一条记录？") != true){
							return;
						}
						return sRecordID;
					}
                    sRecordID = ob_arr[i].value;
                    count = count + 1;
                }
            }
        }
    }
    if(sRecordID == null || sRecordID == ""){
        alert("请选择记录!");
		return;
    }else
        return sRecordID;
}

/**
* 得到一条记录对象
*/
function getOneRecordObj(name){
	var sRecord,sFeatures,sHref;
	var count = 0;
    var ob_arr = $name(name);
    if (ob_arr == null)
    {
        alert("请选择记录！");
        return;
    }else{
        if (ob_arr.length == null){
            if(ob_arr.checked)
                sRecord = ob_arr;
            else{
                alert("请选择记录！");
                return;
            }
        }else{
            for (i=0;i<ob_arr.length;i++){
                if (ob_arr[i].checked == true){
					if(count != 0){
						if(confirm("此操作为单选，你选择了多条记录，是否取第一条记录？") != true){
							return;
						}
						return sRecord;
					}
                    sRecord = ob_arr[i];
                    count = count + 1;
                }
            }
        }
    }
    if(sRecord==null||sRecord.value == null || sRecord.value == ""){
        alert("请选择记录!");
		return;
    }else
        return sRecord;
}


/**
* 得到所有选中记录编号
*/
function getAllRecord(){
    var sRecordID = "";
	var sFeatures,sHref;
    var ob_arr = $name("query_checkbox");
    if (ob_arr == null)
    {
        alert("请选择记录！");
        return;
    }else{
        if (ob_arr.length == null){
            if(ob_arr.checked)
                sRecordID = ob_arr.value;
            else{
                alert("请选择记录！");
                return;
            }
        }else{
            for (i=0;i<ob_arr.length;i++){
                if (ob_arr[i].checked == true){
					if(sRecordID != null && sRecordID != "")
						sRecordID = sRecordID + ",";
                    sRecordID = sRecordID + ob_arr[i].value;
                }
            }
        }
    }
    if(sRecordID == null || sRecordID == ""){
        alert("请选择记录!");
		return;
    }else
        return sRecordID;
}



/**
* 得到所有选中记录编号
*/
function getAllRecordArray(name) {
    var sRecord = new Array();
    var ob_arr = $name(name);
    var j = 0;
    if (ob_arr != null)
	    if (ob_arr.length == null) {
	        if(ob_arr.checked)
	            sRecord[0] = ob_arr;
	    } else for(i = 0; i < ob_arr.length; i++) {
	        if (ob_arr[i].checked == true)
	            sRecord[j++] = ob_arr.item(i);
	    }
    if (sRecord.length == 0)
        alert("请选择记录!");
    return sRecord;
}

function getAllSelectedOptionValue(name) {
    var sRecord = "";
    var ob_arr = document.all.item(name);
    var j = 0;
    if (ob_arr != null)
	    if (ob_arr.length == null) {
	        if(ob_arr.checked)
	            sRecord = ob_arr.value;
	    } else for(i = 0; i < ob_arr.length; i++) {
	        if (ob_arr.item(i).checked == true){
	           if (sRecord!="")
	           		sRecord += ",";
	           sRecord += ob_arr.item(i).value;
	        }
	    }
    return sRecord;
}

function querySubmit(formName){
	if(CheckAction() == true){
		document.all.item(formName).submit();
	}
}


function $(o){return document.getElementById(o);}
function $name(o){return document.getElementsByName(o);}


//OnClick改变底色，并Check
function ClickCheck(it)
{
  var ob_arr = $name("query_checkbox");
  var currentClickObj = window.event.srcElement;
  if(currentClickObj.tagName.toLowerCase()=="input")
    return;
  if ( ob_arr == null)
    return;
  if(ob_arr.length == null){
  	if(it.index == 1){
		ob_arr.checked = !ob_arr.checked;
    	it.className = "query_list_data_trSelected";
  	}
  }else{
    //判断点击列表空记录处
    if(it.index>ob_arr.length)
            return;
    for(i=0;i<ob_arr.length;i++){
      //ob_arr[i].checked = false;
      //ob_arr[i].parentElement.parentElement.className = (i%2==1)?"query_list_data_tr1":"query_list_data_tr2";
    }
    ob_arr[it.index-1].checked = !ob_arr[it.index-1].checked;
    //ob_arr[it.index-1].parentElement.parentElement.className = "query_list_data_trSelected";
  }
}


//点击列表的某一个checkbox时，令该checkbox所在的tr显示为被选中状态
function listCheckboxClick(){
  var obj = window.event.srcElement;
  var ppObj = obj.parentElement.parentElement;
  var i = ppObj.index-1;
  if(obj.checked != true){
    ppObj.className = (i%2==1)?"query_list_data_tr1":"query_list_data_tr2";
  }
  if(obj.checked == true){
    ppObj.className = "query_list_data_trSelected";
  }
}
